package com.you.redisqueue.producer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import java.util.List;

/**
 *
 * 将数据放入redis队列
 * @Author: weiwei.you
 * @Date: 2020-11-13 19:28
 */

@Component
public class RedisProducer {

    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    public void putData(String queueName,Object object){
        Assert.notNull(object,"对象不应为空");
        redisTemplate.opsForList().leftPush(queueName,object);
    }

    public void putList(String queueName, List<Object> list){
        Assert.notEmpty(list,"列表不应为空");
        redisTemplate.opsForList().leftPushAll(queueName,list);
    }

}
